package com.xcesys.extras.remoting;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ResourceBundleMessageSource;

import com.xcesys.extras.core.audit.service.TlAuditLogService;
import com.xcesys.extras.core.resource.ExtrasMessageSource;
import com.xcesys.extras.core.util.DateUtil;
import com.xcesys.extras.system.service.TsSettingService;

/**
 * <p>
 * Base remoting service class is a super class for all web service implementor
 * classes.
 * 
 * <p>
 * This class is intended to be sub-class ,and also intended to be extended in
 * the future.
 * 
 * @author Danne
 */
public abstract class BaseRemotingServiceImpl implements RemotingService {
	/** log instance. */
	protected final Log log = LogFactory.getLog(getClass());

	@Autowired(required = false)
	protected ResourceBundleMessageSource messageSource = new ExtrasMessageSource();

	@Autowired(required = false)
	protected TlAuditLogService auditService;

	@Autowired
	protected TsSettingService settingService;

	protected void auditCreate(Object... obj) {
		if (auditService == null) {
			return;
		}
		auditService.auditCreate(null, obj);
	}

	protected void auditRemove(Object... obj) {
		if (auditService == null) {
			return;
		}
		auditService.auditRemove(null, obj);
	}

	protected void auditUpdate(Object... obj) {
		if (auditService == null) {
			return;
		}
		auditService.auditUpdate(null, obj);
	}

	public String getSettingValueByModuleAndName(Long moduleId, String name,
			String defaultValue) {
		return settingService.getValueByModuleAndName(moduleId, name,
				defaultValue);
	}

	@Override
	public Date getSystemDate() {
		return DateUtil.getCurrentDate();
	}
}